﻿/*
 *   Copyright 2011 Peter Crossley
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *  ----------------------------------------------------------------------------
 *  File:       BasicService.cs
 *  Author:     Peter Crossley
 *  ----------------------------------------------------------------------------
 */
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Management;
using System.DirectoryServices;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
using UEC.Modules.Configuration;

namespace UEC.Modules.Configuration
{
    public class ConfigurationService : ICloudModule
    {
        private CloudManager manager;

        public ConfigurationService(CloudManager manager)
        {
            this.manager = manager;
        }


        public static CloudInit DeserializeCloudInitFromXML(string xml)
        {
            if (String.IsNullOrEmpty(xml))
            {
                return new CloudInit();
            }
            XmlSerializer deserializer = new XmlSerializer(typeof(CloudInit));
            TextReader textReader = new StringReader(xml);
            CloudInit cloudInit = (CloudInit)deserializer.Deserialize(textReader);
            textReader.Close();

            return cloudInit;
        }

        public static string SerializeCloudInitToXML(CloudInit cloud)
        {
            if (cloud == null)
            {
                return null;
            }
            XmlSerializer serializer = new XmlSerializer(typeof(CloudInit));
            StringWriter writer = new StringWriter();
            serializer.Serialize(writer, cloud);
            writer.Close();

            return writer.ToString();
        }


        public static string CONFIG_SETTINGS
        {
            get { return "ConfigSettings"; }
        }

        #region ICloudModule Members

        public string GetServiceName()
        {
            return global::UEC.Properties.Resources.ConfigurationBuilder;
        }

        public System.Windows.Forms.UserControl GetConfigurationControl()
        {
            this.configBuilder = new ConfigBuilder(this);
            return configBuilder;
        }

        public decimal GetWeight()
        {
            return global::UEC.Properties.Settings.Default.ServiceWeight;
        }

        public CloudManager Manager
        {
            get { return manager; }
        }

        private ConfigBuilder configBuilder;
        #endregion

    }
}
